﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using AzureStorageMapper.Criterias.TableStorage;

namespace AzureStorageMapper.Tests.Criterias.TableStorage
{
    [TestFixture]
    public class TableQueryUtilsTests
    {

        private Criteria _crit1;
        private Criteria _crit2;
        private Restrietion _rest1;
        private Restrietion _rest2;
        
        [SetUp]
        public void TestSetUp()
        {
            _crit1 = new Criteria();
            _crit2 = new Criteria();
            _rest1 = new Restrietion();
            _rest2 = new Restrietion();
            
            _crit1.QueryColumn("col1").QueryOperation(CriteriaOperator.Equal).QueryValue("value 1");
            _crit2.QueryColumn("col1").QueryOperation(CriteriaOperator.Equal)
                .QuerySubCriteria.QueryColumn("col2").QueryOperation(CriteriaOperator.GreaterThanOrEqual)
                    .QuerySubCriteria.QueryColumn("col3").QueryOperation(CriteriaOperator.LessThanOrEqueal).QueryValue(12345L);

            _rest1.And(_crit1, _crit2);
            _rest2.Not(_crit1);
        }

        [Test]
        public void GetStringQuery_Criteria_Test()
        {
            string queryStr = TableQueryUtils.GetStringQuery(_crit1);
            Assert.AreEqual("col1 eq value 1", queryStr);

            queryStr = TableQueryUtils.GetStringQuery(_crit2);
            Assert.AreEqual("col1 eq (col2 ge (col3 le 12345))", queryStr);
        }

        [Test]
        public void GetStringQuery_Restrietion_Test()
        {
            string queryStr = TableQueryUtils.GetStringQuery(_rest1);
            Assert.AreEqual("(col1 eq value 1) and (col1 eq (col2 ge (col3 le 12345)))", queryStr);

            queryStr = TableQueryUtils.GetStringQuery(_rest2);
            Assert.AreEqual("not(col1 eq value 1)", queryStr);
        }
    }
}
